package vanjalee.bs.com.control;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

import vanjalee.bs.com.FileSearch;

public class StaticValuesController {

	public static String weaponCloseCombatUrl;
	public static String weaponLongRangeUrl;
	public static String weaponMainCannonUrl;
	public static String weaponSubgunUrl;

	public static String partFigureheadUrl;
	public static String partSailUrl;
	public static String partStabilizerUrl;
	public static String partHullUrl;
	public static String partEngineUrl;

	public static String craftedWeaponCloseCombatUrl;
	public static String craftedWeaponLongRangeUrl;
	public static String craftedWeaponMainCannonUrl;
	public static String craftedWeaponSubgunUrl;

	public static String craftedPartFigureheadUrl;
	public static String craftedPartSailUrl;
	public static String craftedPartStabilizerUrl;
	public static String craftedPartHullUrl;
	public static String craftedPartEngineUrl;

	private static Properties properties = new Properties();

	static {
		try {
			File file = new File(FileSearch.findFile("application.properties"));
			if (file.length() != 0) {

				properties.load(new FileInputStream(file));

				weaponCloseCombatUrl = getValueFor("weaponCloseCombat.url");
				weaponLongRangeUrl = getValueFor("weaponLongRange.url");
				weaponMainCannonUrl = getValueFor("weaponMainCannon.url");
				weaponSubgunUrl = getValueFor("weaponSubgun.url");

				partEngineUrl = getValueFor("partEngine.url");
				partFigureheadUrl = getValueFor("partFigurehead.url");
				partHullUrl = getValueFor("partHull.url");
				partSailUrl = getValueFor("partSail.url");
				partStabilizerUrl = getValueFor("partStabilizer.url");

				craftedWeaponCloseCombatUrl = getValueFor("craftedWeaponCloseCombat.url");
				craftedWeaponLongRangeUrl = getValueFor("craftedWeaponLongRange.url");
				craftedWeaponMainCannonUrl = getValueFor("craftedWeaponMainCannon.url");
				craftedWeaponSubgunUrl = getValueFor("craftedWeaponSubgun.url");

				craftedPartEngineUrl = getValueFor("craftedPartEngine.url");
				craftedPartFigureheadUrl = getValueFor("craftedPartFigurehead.url");
				craftedPartHullUrl = getValueFor("craftedPartHull.url");
				craftedPartSailUrl = getValueFor("craftedPartSail.url");
				craftedPartStabilizerUrl = getValueFor("craftedPartStabilizer.url");

			} else {
				System.out.println("File doesn't exist!");
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static String getValueFor(String key) {
		return properties.getProperty(key);
	}

	public static String setValueFor(String key, String value) {
		properties.setProperty(key, value);
		try {
			properties.store(new FileOutputStream("application.properties"),
					null);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return getValueFor(key);
	}

	public static String getWeaponCloseCombatUrl() {
		return weaponCloseCombatUrl;
	}

	public static String getWeaponLongRangeUrl() {
		return weaponLongRangeUrl;
	}

	public static String getWeaponMainCannonUrl() {
		return weaponMainCannonUrl;
	}

	public static String getWeaponSubgunUrl() {
		return weaponSubgunUrl;
	}

	public static String getPartFigureheadUrl() {
		return partFigureheadUrl;
	}

	public static String getPartSailUrl() {
		return partSailUrl;
	}

	public static String getPartStabilizerUrl() {
		return partStabilizerUrl;
	}

	public static String getPartHullUrl() {
		return partHullUrl;
	}

	public static String getPartEngineUrl() {
		return partEngineUrl;
	}

	public static String getCraftedWeaponCloseCombatUrl() {
		return craftedWeaponCloseCombatUrl;
	}

	public static String getCraftedWeaponLongRangeUrl() {
		return craftedWeaponLongRangeUrl;
	}

	public static String getCraftedWeaponMainCannonUrl() {
		return craftedWeaponMainCannonUrl;
	}

	public static String getCraftedWeaponSubgunUrl() {
		return craftedWeaponSubgunUrl;
	}

	public static String getCraftedPartFigureheadUrl() {
		return craftedPartFigureheadUrl;
	}

	public static String getCraftedPartSailUrl() {
		return craftedPartSailUrl;
	}

	public static String getCraftedPartStabilizerUrl() {
		return craftedPartStabilizerUrl;
	}

	public static String getCraftedPartHullUrl() {
		return craftedPartHullUrl;
	}

	public static String getCraftedPartEngineUrl() {
		return craftedPartEngineUrl;
	}

	public static Properties getProperties() {
		return properties;
	}

}
